﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using WordServices.HttpService;
using WordsOfLove.ForumPages;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace WordsOfLove
{
	public class Sentence
	{
		public int Id { get; set; }
		public string Word { get; set; }
		public string Content { get; set; }
		public int UserId { get; set; }
	}

	public sealed partial class ContributeDialog : ContentDialog
	{
		public ContributeDialog()
		{
			this.InitializeComponent();
		}

		public string Word { get; set; }

		private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
		{
			HttpUtils utils = HttpUtilsFactory.Utils;
			try
			{
				utils.SendPostMessage("api/Sentence/CreateSentence", new Sentence()
				{
					Content = SentenceBox.Text,
					UserId = CurrentUserFactory.CurrentUserId,
					Word = Word
				});
			}
			catch
			{
				new MessageDialog("服务器错误").ShowAsync();
			}
		}
	}
}
